package cn.meizhu.pet.service.impl;

import cn.meizhu.base.service.impl.BaseServiceImpl;
import cn.meizhu.org.domain.Employee;
import cn.meizhu.pet.domain.Pet;
import cn.meizhu.pet.domain.PetDetail;
import cn.meizhu.pet.mapper.PetDetailMapper;
import cn.meizhu.pet.mapper.PetMapper;
import cn.meizhu.pet.service.IPetService;
import cn.meizhu.user.domain.LoginInfo;
import cn.meizhu.util.AjaxResult;
import cn.meizhu.util.LoginContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Set;

@Service
public class PetServiceImpl  extends BaseServiceImpl<Pet> implements IPetService {

    @Autowired
    private PetMapper petMapper;
    @Autowired
    private PetDetailMapper petDetailMapper;

    @Override
    public void onsale(List<Long> list) {
        petMapper.onsale(list);
    }

    @Override
    public void offsale(List<Long> list) {
        petMapper.offsale(list);
    }

    @Override
    public void save(Pet pet, HttpServletRequest request) {
        //获取用户信息
        Employee employee = (Employee) LoginContext.loginContextUser(request);
        pet.setShop_id(employee.getShop_id());
        super.save(pet);
        pet.getDetail().setPet_id(pet.getId());
        petDetailMapper.save(pet.getDetail());
    }

    @Override
    public Pet findByIdDetail(Long id) {
        Pet pet = petMapper.findByIdDetail(id);
        PetDetail detail = petDetailMapper.findByPetId(pet.getId());
        pet.setDetail(detail);
        return pet;

    }
}
